package web;

import java.util.List;

import model.League;
import model.User;
import service.LeagueService;
import service.PlayerStandingService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

/**
 * Class for manipulates actions of the League in web application
 * @author Andre Melo
 * @author Marcus Leite 
 * @author Sergio Danilo
 * 
 */
public class PlayerStandingAction extends BLMSAction implements Preparable {

	private static final long serialVersionUID = -774001762904187788L;

	//Attributes
	private PlayerStandingService playerStandingService;
	
	private LeagueService leagueService;
	
	private Integer leagueId;
	
	private Integer userId;
	
	private String expression;
	
	private List<League> leagues;
	
	private List<User> users;
	
	/**
	 * The main method for web application
	 * 
	 * @return Success or fail in the application
	 */
	public String main() {
		return Action.SUCCESS;
	}
	
	/**
	 * The input method
	 * @return
	 */
	public String input() {
		return Action.INPUT;
	}
	
	/**
	 * Save the league application
	 * @return All leagues
	 */
	public String save() {
		try {
			System.out.println("Saving new standing");
			playerStandingService.defineStandingsExpression(leagueId, expression);
		} catch (Exception e) {
			e.printStackTrace();
			return Action.INPUT;
		}
		return Action.SUCCESS;
	}
		
	
	@Override
	public void prepare() throws Exception {
		users = userService.listAll();
		leagues = leagueService.listAll();
		
	}

	/**
	 * Get the standing expression.
	 * @return The standing expression.
	 */
	public String getExpression() {
		return expression;
	}

	/**
	 * Set the standing expression.
	 * @param expression The standing expression.
	 */
	public void setExpression(String expression) {
		this.expression = expression;
	}

	/**
	 * Get an instance of PlayerStanding.
	 * @return An instance of PlayerStanding.
	 */
	public PlayerStandingService getPlayerStandingService() {
		return playerStandingService;
	}

	/**
	 * Set an instance of PlayerStanding.
	 * @param playerStandingService An instance of PlayerStanding.
	 */
	public void setPlayerStandingService(PlayerStandingService playerStandingService) {
		this.playerStandingService = playerStandingService;
	}

	/**
	 * Get an instance of LeagueService.
	 * @return An instance of LeagueService.
	 */
	public LeagueService getLeagueService() {
		return leagueService;
	}

	/**
	 * Set an instance of LeagueService.
	 * @param leagueService An instance of LeagueService.
	 */
	public void setLeagueService(LeagueService leagueService) {
		this.leagueService = leagueService;
	}

	/**
	 * Get the ID of the league.
	 * @return The ID of the league.
	 */
	public Integer getLeagueId() {
		return leagueId;
	}

	/**
	 * Set the ID of the league.
	 * @param leagueId The ID of the league.
	 */
	public void setLeagueId(Integer leagueId) {
		this.leagueId = leagueId;
	}

	/**
	 * Get the ID of the user.
	 * @return The ID of the user.
	 */
	public Integer getUserId() {
		return userId;
	}

	/**
	 * Set the ID of the user.
	 * @param userId The ID of the user.
	 */
	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	/**
	 * Get a list of leagues.
	 * @return A list of leagues.
	 */
	public List<League> getLeagues() {
		return leagues;
	}

	/**
	 * Set a list of leagues.
	 * @param leagues A list of leagues.
	 */
	public void setLeagues(List<League> leagues) {
		this.leagues = leagues;
	}

	/**
	 * Get a list of users.
	 * @return A list of users.
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * Set a list of users.
	 * @param users A list of users.
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}


}
